from timeit import Timer

import sys
import math


def Problem():
    """A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
                    a^(2) + b^(2) = c^(2)        (1)

    For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2).

    There exists exactly one Pythagorean triplet for which a + b + c = 1000    (2).
    Find the product abc. """
    
    #Found by substituting (1) into (2)
    a = lambda b: (1000**2 - 2000*b)/(2000 - 2*b)
    # (1)
    c = lambda a, b: (a**2 + b**2)**0.5
    #Calculate (a,b,c) tuple
    t = [ (a(b), b, c(a(b), b)) for b in xrange(500)]
    #Filter and calculate a*b*c 
    ans = [ x*y*z for (x,y,z) in t if x < y and y < z and float(int(z)) == z ]

    print "Answer for Problem 9 = %d " % (ans[0],)



    
if __name__ == "__main__":
    t = Timer(setup='from __main__ import Problem', stmt='Problem()').timeit(1)
    print "Execution time = %0.3f seconds" %(t,)